package com.adee.netty.tcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

public class MyMessageDecoder extends ReplayingDecoder<Void> {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        int len = in.readInt(); // 读取MessageProtocol对象的第一个属性，int类型
        byte[] bytes = new byte[len];
        in.readBytes(bytes);
        MessageProtocol mp = new MessageProtocol(bytes);
        out.add(mp);
//        out.add(mp.getLen());
//        out.add(mp.getContent());
    }
}
